package com.example.mysports.ui

import androidx.lifecycle.ViewModel
import com.example.mysports.data.LocalSportsDataProvider
import com.example.mysports.model.Sport
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class SportViewModel : ViewModel() {
    private val _uiState = MutableStateFlow(SportUiState())
    val uiState: StateFlow<SportUiState> = _uiState.asStateFlow()

    init {
        initializeUiState()
    }
    private fun initializeUiState() {
        val sports = LocalSportsDataProvider.getSportsList()
        _uiState.value = SportUiState(sports = sports, currentSport = sports[0])
    }

    fun resetHomeScreenStates() {
        _uiState.update {
            it.copy(
                isShowingHomepage = true
            )
        }
    }

    fun updateCurrentSport(sport: Sport) {
        _uiState.update {
            it.copy(
                currentSport = sport,
                isShowingHomepage = false
            )
        }
    }
}